package com.bible.fire.api.baidumap;

import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.mapapi.map.LocationData;
import com.bible.fire.local.AppContext;
import com.bible.fire.util.AndroidUtil;

public class LocationListenerFromBaidu implements BDLocationListener {

	LocationData locData = null;
	
	@Override
	public void onReceiveLocation(BDLocation location) {
		if (location == null || location.getLatitude() == 4.9E-324 || location.getLongitude() == 4.9E-324 ){
			//Toast.makeText(AppContext.getContext(), "百度定位服务无法获取当前位置", Toast.LENGTH_LONG).show();
			double[] pos = AndroidUtil.getCurrentLocation();
			if( pos != null ){
				//Toast.makeText(AppContext.getContext(), "即时定位地址: latitude:" + pos[0] + ",longitude:" + pos[1], Toast.LENGTH_LONG).show();
			}
            return ;
		}
		
		LocationData locData = (LocationData)AndroidUtil.getAttribute("locationData");
		if( locData == null ){
			locData = new LocationData();
			AndroidUtil.setAttribute( "locationData", locData );
		}
		locData.latitude = location.getLatitude();
        locData.longitude = location.getLongitude();
        locData.accuracy = location.getRadius();
        locData.direction = location.getDerect();
        //Toast.makeText(AppContext.getContext(), "百度定位地址：latitude:" + locData.latitude + ",longitude:" + locData.longitude, Toast.LENGTH_LONG).show();
	}

	@Override
	public void onReceivePoi(BDLocation poiLocation) {
		if (poiLocation == null){
            return ;
        }
	}

}
